package com.lxmes.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.business.domain.CcStockInfoJs;
import com.lxmes.business.service.ICcStockInfoJsService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 库存计算规则Controller
 * 
 * @author 张志煜
 * @date 2023-01-10
 */
@RestController
@RequestMapping("/business/stockInfoJs")
public class CcStockInfoJsController extends BaseController
{
    @Autowired
    private ICcStockInfoJsService ccStockInfoJsService;

    /**
     * 查询库存计算规则列表
     */
    @PreAuthorize("@ss.hasPermi('business:stockInfoJs:list')")
    @GetMapping("/list")
    public TableDataInfo list(CcStockInfoJs ccStockInfoJs)
    {
        startPage();
        List<CcStockInfoJs> list = ccStockInfoJsService.selectCcStockInfoJsList(ccStockInfoJs);
        return getDataTable(list);
    }

    /**
     * 导出库存计算规则列表
     */
    @PreAuthorize("@ss.hasPermi('business:stockInfoJs:export')")
    @Log(title = "库存计算规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CcStockInfoJs ccStockInfoJs)
    {
        List<CcStockInfoJs> list = ccStockInfoJsService.selectCcStockInfoJsList(ccStockInfoJs);
        ExcelUtil<CcStockInfoJs> util = new ExcelUtil<CcStockInfoJs>(CcStockInfoJs.class);
        util.exportExcel(response, list, "库存计算规则数据");
    }

    /**
     * 获取库存计算规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:stockInfoJs:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ccStockInfoJsService.selectCcStockInfoJsById(id));
    }

    /**
     * 新增库存计算规则
     */
    @PreAuthorize("@ss.hasPermi('business:stockInfoJs:add')")
    @Log(title = "库存计算规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CcStockInfoJs ccStockInfoJs)
    {
        return toAjax(ccStockInfoJsService.insertCcStockInfoJs(ccStockInfoJs));
    }

    /**
     * 修改库存计算规则
     */
    @PreAuthorize("@ss.hasPermi('business:stockInfoJs:edit')")
    @Log(title = "库存计算规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CcStockInfoJs ccStockInfoJs)
    {
        return toAjax(ccStockInfoJsService.updateCcStockInfoJs(ccStockInfoJs));
    }

    /**
     * 删除库存计算规则
     */
    @PreAuthorize("@ss.hasPermi('business:stockInfoJs:remove')")
    @Log(title = "库存计算规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ccStockInfoJsService.deleteCcStockInfoJsByIds(ids));
    }
}
